package edu.stu.mall.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.lifecycle.MutableLiveData
import androidx.recyclerview.widget.RecyclerView
import edu.stu.mall.databinding.ItemAttributeListBinding

class ProductAttributeAdapter : RecyclerView.Adapter<ProductAttributeAdapter.ProductAttributeViewHolder>() {

    private var dataList: Map<String, String> = HashMap()
    fun setData(list: Map<String, String>) {
        if (list != null && list.isNotEmpty()) {
            dataList = list
            notifyDataSetChanged()
        }
    }


    class ProductAttributeViewHolder(binding: ItemAttributeListBinding) : RecyclerView.ViewHolder(binding.root) {
        var itemBinding: ItemAttributeListBinding

        init {
            itemBinding = binding
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductAttributeViewHolder {

        return ProductAttributeViewHolder(
            ItemAttributeListBinding.inflate(
                LayoutInflater.from(parent.context),
                parent, false
            )
        )
    }

    override fun getItemCount(): Int {
        return dataList.size

    }

    override fun onBindViewHolder(holder: ProductAttributeViewHolder, position: Int) {
        holder.itemBinding.itemHomeTitle.text = dataList.keys.elementAt(position)
        holder.itemBinding.itemHomeValue.text = dataList.values.elementAt(position)
    }
}